#include "Program.h"


Program::Program(std::string fileName)
{
	std::ifstream file(fileName.c_str());

	if(file.is_open())
	{
		file>>size;
		size++;
		states = new State[1<<size]();
		for(int i = 1;i<size;i++)
		{
			file>>states[i].p;
			file>>states[i].w;
			file>>states[i].t;
		}
		Run();
	}
	else
	{
		std::cout<<"Bad file name or file not exists."<<std::endl;
	}
}
void Program::Run()
{
	algorithm = new Algorithm(states,size);
	time_t start,stop;
	time(&start);
	algorithm->Calculate();
	time(&stop);
	std::cout<<"Size : "<<size-1;
	std::cout<<" Duration :"<<(stop - start)<<" s WiTi : "<<
		algorithm->GetMinWiTi()<<std::endl;
}
Program::~Program()
{
	if(size>0)
		delete [] states;
}